﻿using System.Web;
using System.Web.UI;
using DreamDriven.ObjectModel.Mvp;

namespace DreamDriven.Web
{
    /// <summary>
    /// Represents a user control that is a view in a Web Forms Model-View-Presenter application
    /// </summary>
    public abstract class BaseUserControl : UserControl, IViewStateControl
    {
        /// <summary>
        /// Gets a dictionary of state information that allows you to save and 
        /// restore the view state of a server control across multiple requests for the same page.
        /// </summary>
        /// <value></value>
        /// <returns>An instance of the <see cref="T:System.Web.UI.StateBag"/> class that contains the server control's view-state information.</returns>
        public new StateBag ViewState
        {
            get { return base.ViewState; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="BaseUserControl"/> class.
        /// </summary>
        protected BaseUserControl()
        {
            PresenterBinder.Bind(this);
        }

        public string CurrentUserName
        {
            get
            {
                return HttpContext.Current.User.Identity.IsAuthenticated
                           ? HttpContext.Current.User.Identity.Name
                           : string.Empty;
            }
        }
    }
}